package my.graduation.util;

/**
 * @Author: RavenLyn
 * @Date: 2024-12-13
 */
import java.time.LocalDate;
import java.time.DayOfWeek;

public class DateCalculator {

    public static LocalDate calculateNextMondayDate() {

        // 计算今天是周几
        LocalDate today = LocalDate.now();
        DayOfWeek dayOfWeek = today.getDayOfWeek();

        // 计算到下周一还需要的天数
        long daysToMonday = DayOfWeek.MONDAY.getValue() - dayOfWeek.getValue();

        // 如果给定日期是周一或之后，减去7天以计算到下周一
        if (daysToMonday <= 0) {
            daysToMonday += 7;
        }
        // 返回下周一的日期
        return today.plusDays(daysToMonday);
    }

    public static LocalDate calculateNextSaturdayDate() {
        LocalDate nextMonday = calculateNextMondayDate();//基于下周一去计算下周六
        return nextMonday.plusDays(5);

//        // 计算今天是周几
//        LocalDate today = LocalDate.now();
//        DayOfWeek dayOfWeek = today.getDayOfWeek();
//
//        // 计算到下周六还需要的天数
//        long daysToSaturday = DayOfWeek.SATURDAY.getValue() - dayOfWeek.getValue();
//
//        // 如果给定日期是周六或之后，减去7天以计算到下周六
//        if (daysToSaturday <= 0) {
//            daysToSaturday += 7;
//        }
//
//        // 返回下周一的日期
//        return today.plusDays(daysToSaturday);
    }

    public static int getDayOfWeekAsInt(LocalDate date) {
        DayOfWeek dayOfWeek = date.getDayOfWeek();
        return dayOfWeek.getValue();
    }

    public static void main(String[] args) {
        // 输出结果
        System.out.println("下个周一是: " + calculateNextMondayDate());
        System.out.println("下个周六是: " + calculateNextSaturdayDate());
        System.out.println("周几计算："+getDayOfWeekAsInt(LocalDate.now()));
    }
}
